<?php
define('AJAX_SCRIPT', true);
require_once('../../config.php');
require_once('./lib.php');

$action = required_param('do', PARAM_TEXT);

$sts_id = $_POST["sts_id"];


$mylib = new survey_management();

if($action=='comment')
{
    
}else if($action=='assess')
{
    $lo_id = $_POST["lo_id"];
    $content = $_POST["content"];
    
    //check if exist the assessment or not
    $id = $mylib->isAssessExist($sts_id,$lo_id);
    if($id > 0){
        echo "update";
        $mylib->updateAssessTeachMethod($id,$content);
    }else{
        echo "new";
        $mylib->saveAssessTeachMethod($sts_id,$lo_id,$content);
    }
       
}else if($action=='check')
{
    $lo_id = $_POST["lo_id"];
    $content = $_POST["content"];

    $typeOfValue = $_POST["typeOfValue"];
    $id = $mylib->getITUValue($sts_id,$lo_id,$typeOfValue);
    
    if($id > 0){
        //delete
        $mylib->deleteITUValue($id);
    }else{
        //new        
        $mylib->saveITUValue($sts_id, $lo_id, $typeOfValue);
    }
}else if($action == "answer"){
    $question_id = $_POST["question_id"];
    $input = $_POST["input"];    
    $typeOfQuestion = $_POST["typeOfQuestion"];
    
    if($typeOfQuestion == "1"){
        $mylib->save_answer($sts_id,$question_id,$input,$typeOfQuestion);
    }else if($typeOfQuestion == "2"){
        $mylib->save_answer($sts_id,$question_id,$input,$typeOfQuestion);
    }else if($typeOfQuestion == "3"){
        $state = $_GET["state"];
        $mylib->save_answer_of_checkbox($sts_id,$question_id,$input,$state);        
    }else if($typeOfQuestion == "4"){
        $mylib->save_answer($sts_id,$question_id,$input,$typeOfQuestion);
    }
}
?>